﻿using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using NineSeas.Models;
using Orchard.Data;
using JetBrains.Annotations;
using Orchard.Roles.Services;
using Orchard.Roles.Models;
using Orchard;
using Orchard.Users.Models;
using Orchard.Security;

namespace NineSeas.Handlers
{
    public class AuthorProfileHandler : ContentHandler 
    {
        [UsedImplicitly]
        public AuthorProfileHandler(IRepository<AuthorProfilePartRecord> repository,
            IRepository<UserRolesPartRecord> userRolesRepository,
            IRoleService roleService,
            IOrchardServices services)
        {
            Filters.Add(StorageFilter.For(repository));

            OnCreated<AuthorProfilePart>((context, part) =>
            {
                //var user = part.As<UserPart>();
                //var role = roleService.GetRoleByName("Author");

                //if (user != null && role != null)
                //{
                //    userRolesRepository.Create(
                //        new UserRolesPartRecord
                //        {
                //            UserId = user.As<IUser>().Id,
                //            Role = role
                //        });
                //}
            });
        }
    }
}